//
//  HotListTableViewCell.m
//  WisdomZhuHai
//
//  Created by JasonLee on 14/12/9.
//  Copyright (c) 2014年 wyd. All rights reserved.
//

#import "HotListTableViewCell.h"
#import "HotListModel.h"
#import "Common.h"

#define HLColor(r,g,b) [UIColor colorWithHue:r/255.0 saturation:g/255.0 brightness:b/255.0 alpha:1] //颜色宏定义
#define HLTableViewCellControlSpacing 10 //控件间距
#define HLTableViewCellBackground HLColor(251, 251, 251)
#define HLGrayColor HLColor(50, 50, 50)
#define HLLightGrayColor HLColor(120, 120, 120)

#define HLTableViewCellAvatarWidth 40 //图像宽度
#define HLTableViewCellAvatarHeight HLTableViewCellAvatarWidth
#define HLTableViewCellTitleFontSize 14
#define HLTableViewCellDetailFontSize 12

@interface HotListTableViewCell(){
    UIImageView *_avatar; //头像
    UILabel *_title;
    UILabel *_detail;
}

@end

@implementation HotListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self initSubView];
    }
    return self;
}

#pragma mark - 初始化试图
- (void) initSubView{
    _avatar = [[UIImageView alloc]init];
    [self addSubview:_avatar];
    
    _title = [[UILabel alloc]init];
    _title.textColor = HLGrayColor;
    _title.font = [UIFont systemFontOfSize:HLTableViewCellTitleFontSize];
    [self addSubview:_title];
    
    _detail = [[UILabel alloc]init];
    _detail.textColor = HLLightGrayColor;
    _detail.font = [UIFont systemFontOfSize:HLTableViewCellDetailFontSize];
    [self addSubview:_detail];
}

#pragma mark - 设置单元格
- (void) setModel:(HotListModel *)model{
    //设置图像大小和位置
    if (model == nil) {
        return;
    }
    CGFloat avatarX = 10, avatarY = 10;
    CGRect avatarRect = CGRectMake(avatarX, avatarY, HLTableViewCellAvatarWidth, HLTableViewCellAvatarHeight);
    //_avatar.image = [UIImage imageNamed:model.img_url];
    [_avatar setImageWithURL:[Common getFullDownloadPathByRelativePath:[Common valueForKey:P_PIC_URL dic:model]]];
    _avatar.frame = avatarRect;
    
    //设置标题大小和位置
    CGFloat titleX = CGRectGetMaxX(_avatar.frame) + HLTableViewCellControlSpacing;
    CGFloat titleY = avatarY;
    CGSize titleSize = [[Common valueForKey:P_NAME dic:model] sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:HLTableViewCellTitleFontSize]}];
    CGRect titleRect = CGRectMake(titleX, titleY, titleSize.width, titleSize.height);
    _title.text = [Common valueForKey:P_NAME dic:model];
    _title.frame = titleRect;
   
    //设置详情大小和位置
    CGSize detailSize = [[Common valueForKey:P_SMALL_INTRO dic:model] sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:HLTableViewCellDetailFontSize]}];
    CGFloat detailX = titleX;
    CGFloat detailY = CGRectGetMaxY(_avatar.frame) - detailSize.height;
    //CGFloat detailWidth = self.frame.size.width - HLTableViewCellControlSpacing * 2;
    CGRect detailRect = CGRectMake(detailX, detailY, 220, detailSize.height);
    _detail.text = [Common valueForKey:P_SMALL_INTRO dic:model];
    _detail.frame = detailRect;
    
    _height = CGRectGetMaxY(_detail.frame) + HLTableViewCellControlSpacing;
}

#pragma mark － 重写选择事件，取消选中
- (void) setSelected:(BOOL)selected animated:(BOOL)animated{
    
}


@end
